/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snail.Servlets;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author viktor
 */
public class ViewPictureServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("image/png");

        String id = request.getParameter("id");
        String t = request.getParameter("thumb");

        if (t == null) {
            t = "Big";
        } else {
            t = "Thumb";
        }

        File f = new java.io.File(getServletContext().getRealPath("/Auctions/Images/" + t + "/" + id + ".png"));
        if(!f.exists())
            f = new java.io.File(getServletContext().getRealPath("/Auctions/Images/noimage.png"));
        
        BufferedImage buffer = ImageIO.read(f);
        javax.servlet.ServletOutputStream os = response.getOutputStream();
        ImageIO.write(buffer, "png", os);
        os.close();
    }
}
